package biz.noip.strategy.players;

import org.andengine.extension.tmx.TMXLayer;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

import biz.noip.strategy.mediator.MediatorGame;
import biz.noip.strategy.players.bars.HealthBar;
import biz.noip.strategy.players.weapons.Fireball;
import biz.noip.strategy.scenes.GameScene;

public class MagePlayer extends Player {

	private static final int DAMAGE_MAX = 200;
	private static final int DAMAGE_MIN = 35;
	private static final int MOVE_MAX = 4;
	private static final int ARMOR = 3;
	private static final float CRIT = 0.1f;

	private Fireball fire;

	public static final int MAX_HEALTH = 400;
	private int damage;

	public MagePlayer(int startX, int startY, int pWidth, int pHeight, ITiledTextureRegion pTiledTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager, GameScene gameScene, int team, TMXLayer mTmxLayer) {
		super(startX, startY, pWidth, pHeight, pTiledTextureRegion, pVertexBufferObjectManager, gameScene, team);
		setMove(MOVE_MAX);
		setHealthBar(new HealthBar(this, Color.RED, MAX_HEALTH, pVertexBufferObjectManager));
		registerUpdateBar(getHealthBar());
		setHealth(MAX_HEALTH);
	}

	@Override
	public boolean attack(Player player) {
		fire = new Fireball(this.mX, this.mY, 32, 32, this.scene.textureMap.get("fireball"),
				getVertexBufferObjectManager(), this.scene);
		damage = getDamage(DAMAGE_MIN, DAMAGE_MAX, player.getArmor(), CRIT, getMove());
		mDamageView.setText(((Integer) damage).toString());
		if(isCrit()){
			mDamageView.setTextColor(Color.RED);
			setCrit(false);
		}
		fire.move(player, mDamageView);
		setSelect(false);
		setMove(0);
		return true;
	}

	@Override
	public int getDamage() {
		System.out.println("RAND: " + damage);
		return damage;
	}

	@Override
	public void death() {
		scene.unregisterTouchArea(this);
		getHealthBar().removeBar();
		scene.getGame().deathPlayer(this);
		MediatorGame.getInstance().deleteChild(this, scene);
	}

	@Override
	public int getMaxMove() {
		return MOVE_MAX;
	}

	@Override
	public int getMaxDamage() {
		return DAMAGE_MAX;
	}

	@Override
	public int getMinDamage() {
		return DAMAGE_MIN;
	}

	@Override
	public int getMaxHealth() {
		return MAX_HEALTH;
	}

	@Override
	public int getArmor() {
		return ARMOR;
	}

}